/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConsultaEleccion.java
 *
 * Created on 14/11/2010, 05:00:15 PM
 */
package zonasoft.Vistas.Negocio;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Iterator;
import java.util.List;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import org.jdesktop.swingx.decorator.Filter;
import org.jdesktop.swingx.decorator.FilterPipeline;
import org.jdesktop.swingx.decorator.PatternFilter;
import zonasoft.Conceptos.Lider;
import zonasoft.Conceptos.Zonificados;
import zonasoft.Manejadores.ManejadorBaseDatos;
import zonasoft.Manejadores.ManejadorUsuario;
import zonasoft.Manejadores.ManejadorZonificados;

/**
 *
 * @author JORGE
 */
public class ListarZonificados extends javax.swing.JDialog {

    /** Creates new form ConsultaEleccion */
    public ListarZonificados(java.awt.Frame  parent) {
        super(parent, true);
        initComponents();
        errorLabel.setVisible(false);
        pack();
        Rectangle parentBounds = parent.getBounds();
        Dimension size = getSize();
        // Center in the parent
        int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
        int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
        setLocation(new Point(x, y));

      List<TableColumn> columnas=  tablaSimpatizantes.getColumns();
       columnasTablaSimpa.addItem("..Sin filtro...");
        for (TableColumn tableColumn : columnas) {
            String col= tableColumn.getHeaderValue().toString();
            columnasTablaSimpa.addItem(col);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXTaskPaneContainer1 = new org.jdesktop.swingx.JXTaskPaneContainer();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        aceptar = new javax.swing.JButton();
        listar = new javax.swing.JButton();
        limpiar = new javax.swing.JButton();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jXTaskPaneContainer2 = new org.jdesktop.swingx.JXTaskPaneContainer();
        jLabel28 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        campoIdLider = new javax.swing.JTextField();
        campoNombreLider = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        campoApellidoLider = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaSimpatizantes = new org.jdesktop.swingx.JXTable();
        totalSim = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        filtroText = new javax.swing.JTextField();
        columnasTablaSimpa = new javax.swing.JComboBox();
        errorLabel = new javax.swing.JLabel();

        setTitle("");
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 20));
        jLabel1.setText("Listado de Zonificados");
        jXTaskPaneContainer1.add(jLabel1);

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.gray, java.awt.Color.lightGray, java.awt.Color.gray, java.awt.Color.lightGray));

        aceptar.setFont(new java.awt.Font("Tahoma", 1, 12));
        aceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/ok 32.png"))); // NOI18N
        aceptar.setText("Aceptar");
        aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aceptarActionPerformed(evt);
            }
        });

        listar.setFont(new java.awt.Font("Tahoma", 1, 12));
        listar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/community-users-icon2.png"))); // NOI18N
        listar.setText("Listar");
        listar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listarActionPerformed(evt);
            }
        });

        limpiar.setFont(new java.awt.Font("Tahoma", 1, 12));
        limpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/limpiar.png"))); // NOI18N
        limpiar.setText("Limpiar");
        limpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(listar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
                    .addComponent(aceptar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
                    .addComponent(limpiar, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(listar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(limpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(aceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5))
        );

        jXPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED, java.awt.Color.lightGray, java.awt.Color.lightGray, java.awt.Color.gray, java.awt.Color.gray));

        jLabel28.setBackground(new java.awt.Color(255, 255, 255));
        jLabel28.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel28.setText("Detalle Lider");
        jLabel28.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
        jXTaskPaneContainer2.add(jLabel28);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel7.setText("Identificacion");

        campoIdLider.setEditable(false);

        campoNombreLider.setEditable(false);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel5.setText("Nombres");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel6.setText("Apellidos");

        campoApellidoLider.setEditable(false);

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXTaskPaneContainer2, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addContainerGap(79, Short.MAX_VALUE))
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addContainerGap(109, Short.MAX_VALUE))
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addContainerGap(107, Short.MAX_VALUE))
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(campoApellidoLider, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoNombreLider, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoIdLider, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addComponent(jXTaskPaneContainer2, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(campoIdLider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoNombreLider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(campoApellidoLider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.gray, java.awt.Color.lightGray, java.awt.Color.darkGray, java.awt.Color.gray), "Zonificados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        tablaSimpatizantes.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.blue, new java.awt.Color(51, 102, 255)));
        tablaSimpatizantes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Identificacion", "Nombre","Apellido","Telefono", "Puesto de Votacion", "mesa"
            }
        ));
        //tablaSimpatizantes.setRowSorter (new TableRowSorter(tablaSimpatizantes.getModel()));
        tablaSimpatizantes.setEditable(false);
        /*codigo nuevo*/
        //TableRowSorter sorter = new TableRowSorter(tablaSimpatizantes.getModel());
        //sorter.setRowFilter (RowFilter.regexFilter(".*zxc.*"));
        //tablaSimpatizantes.setRowSorter (sorter);
        /*fin new code*/
        //FilterPipeline filtro = new FilterPipeline(new PatternFilter(filtroText.getText(), 0, 0));
        //tablaSimpatizantes.setFilters(filtro);
        tablaSimpatizantes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaSimpatizantesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablaSimpatizantes);

        totalSim.setEditable(false);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setText("Actualmente hay:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel3.setText("Zonificados  Registradas");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 794, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(totalSim, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(totalSim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)))
        );

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("Filtrar Por");

        filtroText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                filtroTextKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                filtroTextKeyReleased(evt);
            }
        });

        columnasTablaSimpa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                columnasTablaSimpaActionPerformed(evt);
            }
        });

        errorLabel.setForeground(new java.awt.Color(255, 0, 0));
        errorLabel.setText("No  ha seleccionado ningun filtro...");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.DEFAULT_SIZE, 1101, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(columnasTablaSimpa, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(filtroText, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(errorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(columnasTablaSimpa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(filtroText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(errorLabel))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void listarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listarActionPerformed
        // TODO add your handling code here:
        limpiarTabla();
        try {
            listaZonificados();
        } catch (Exception ex) {
            ex.printStackTrace();
            Logger.getLogger(ListarZonificados.class.getName()).log(Level.SEVERE, null, ex);
        }
//              System.out.println("En el action performed del listar");
    }//GEN-LAST:event_listarActionPerformed

    private void aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_aceptarActionPerformed

    private void limpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limpiarActionPerformed
        // TODO add your handling code here:
        limpiarTabla();
    }//GEN-LAST:event_limpiarActionPerformed

    private void tablaSimpatizantesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaSimpatizantesMouseClicked
        // TODO add your handling code here:
        ManejadorBaseDatos mb = ManejadorBaseDatos.getInstancia();

        try {
            mb.conectar();
        } catch (Exception ex) {
            Logger.getLogger(ListarZonificados.class.getName()).log(Level.SEVERE, null, ex);
        }

        ManejadorZonificados.conm = mb.getConexion();
                if (evt.getClickCount() == 1) {
            int fila = tablaSimpatizantes.rowAtPoint(evt.getPoint());
            int columna = tablaSimpatizantes.columnAtPoint(evt.getPoint());
              columna = 0;
            String idT = tablaSimpatizantes.getValueAt(fila, columna).toString();
                    if ((fila > -1) && (columna > -1) && !idT.isEmpty()) {
                      int id = Integer.parseInt(idT);
                Lider l = null;
                try {
                    l = ManejadorZonificados.liderByZonificado(String.valueOf(id));
                    String nombre = l.getNombre();
                    String apellido = l.getApellido();
                    String ide = l.getIdLider();

                    campoIdLider.setText(ide);
                    campoNombreLider.setText(nombre);
                    campoApellidoLider.setText(apellido);

//                System.out.println("nombre = " + nombre);
//                System.out.println("apellido = " + apellido);
//                System.out.println("ide = " + ide);
                } catch (Exception ex) {
                    Logger.getLogger(ListarZonificados.class.getName()).log(Level.SEVERE, null, ex);
                    ex.printStackTrace();
                }
            }
        }
    }//GEN-LAST:event_tablaSimpatizantesMouseClicked

    private void filtroTextKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filtroTextKeyReleased
        hacerLosFiltros();
    }//GEN-LAST:event_filtroTextKeyReleased

    private void hacerLosFiltros()
    {
        try {
            limpiarTabla();
            // TODO add your handling code here:
            String filtro=filtroText.getText();
            int columna=columnasTablaSimpa.getSelectedIndex();
            if(columna>0 && !filtro.isEmpty() && filtro!=null)
            { errorLabel.setVisible(false);
                columna-=1;
            //FilterPipeline filtros = new FilterPipeline(new Filter[] { new PatternFilter(filtro, 0, 0),new PatternFilter(filtro,1, 1) });
            PatternFilter p1 =new PatternFilter(filtro, -1, columna);
                Filter[] filterArray = {p1};
	        FilterPipeline filters = new FilterPipeline(filterArray);
            
            tablaSimpatizantes.setFilters(filters);
            }
            else
            {
            Filter[] filterArray = {};
	    FilterPipeline filters = new FilterPipeline(filterArray);
            tablaSimpatizantes.setFilters(filters);
            if(columna==0 )
            errorLabel.setVisible(true);
            if(filtro==null || filtro.isEmpty())
                errorLabel.setVisible(false);
            }
           
            listaZonificados();
                

        } catch (Exception ex) {
            Logger.getLogger(ListarZonificados.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
        }
    }

    private void filtroTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filtroTextKeyPressed
        // TODO add your handling code here:
        filtroTextKeyReleased(evt);
    }//GEN-LAST:event_filtroTextKeyPressed

    private void columnasTablaSimpaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_columnasTablaSimpaActionPerformed
        // TODO add your handling code here:
        hacerLosFiltros();
    }//GEN-LAST:event_columnasTablaSimpaActionPerformed

    public void listaZonificados() throws Exception {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        mbd.conectar();
        Collection<Zonificados> zon = null;
        try {
            ManejadorZonificados.con = mbd.getConexion();
            zon = (Collection<Zonificados>) ManejadorZonificados.listarZonificados();
            Iterator i = zon.iterator();
            DefaultTableModel dtm = (DefaultTableModel) tablaSimpatizantes.getModel();
            Zonificados zo = new Zonificados();
            tablaSimpatizantes.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
            tablaSimpatizantes.setFont(new java.awt.Font("Tahoma", 0, 13));
            TableColumn tc = tablaSimpatizantes.getColumn("Identificacion"); //Obtienes la columna
            tc.setPreferredWidth(106); //Y le das un tamaño que tu quieras o necesites
            TableColumn tc1 = tablaSimpatizantes.getColumn("Nombre"); //Obtienes la columna
            tc1.setPreferredWidth(146); //Y le das un tamaño que tu quieras o necesites
            TableColumn tc2 = tablaSimpatizantes.getColumn("Apellido"); //Obtienes la columna
            tc2.setPreferredWidth(156); //Y le das un tamaño que tu quieras o necesites
            TableColumn tc3 = tablaSimpatizantes.getColumn("Telefono"); //Obtienes la columna
            tc3.setPreferredWidth(90); //Y le das un tamaño que tu quieras o necesites
            TableColumn tc4 = tablaSimpatizantes.getColumn("Puesto de Votacion"); //Obtienes la columna
            tc4.setPreferredWidth(216); //Y le das un tamaño que tu quieras o necesites
            TableColumn tc5 = tablaSimpatizantes.getColumn("mesa"); //Obtienes la columna
            tc5.setPreferredWidth(80); //Y le das un tamaño que tu quieras o necesites
            //  "Identificacion", "Nombre"," Apellido  ","Telefono ", "----- Puesto de Votacion------", "mesa"
            int r=0;
            while (i.hasNext()) {
                zo = (Zonificados) i.next();
                // String fecha = String.valueOf(li.getFecha_registro());
                Object[] fila = {zo.getIdZonificado(), zo.getNombres(), zo.getApellidos(), zo.getTelefono(), zo.getIdPuesto(), zo.getNumeroMesa()};
//                               System.out.println(zo.getApellidos());
                //                      if(!zo.getIdZonificado().endsWith("_"))
                dtm.addRow(fila);
//                int r = dtm.getRowCount();
                 r++;
               
            }
            int t=tablaSimpatizantes.getFilters().getOutputSize();
            totalSim.setText(String.valueOf(t));
//              System.out.println("en el listar zonificados");
        } catch (Exception ex) {
            ex.printStackTrace();
            Logger.getLogger(ListarZonificados.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void limpiarTabla() {
        DefaultTableModel dtm = (DefaultTableModel) tablaSimpatizantes.getModel();
        dtm.setRowCount(0);
        totalSim.setText("");
        Filter[] filterArray = {};
	    FilterPipeline filters = new FilterPipeline(filterArray);
            tablaSimpatizantes.setFilters(filters);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aceptar;
    private javax.swing.JTextField campoApellidoLider;
    private javax.swing.JTextField campoIdLider;
    private javax.swing.JTextField campoNombreLider;
    private javax.swing.JComboBox columnasTablaSimpa;
    private javax.swing.JLabel errorLabel;
    private javax.swing.JTextField filtroText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXTaskPaneContainer jXTaskPaneContainer1;
    private org.jdesktop.swingx.JXTaskPaneContainer jXTaskPaneContainer2;
    private javax.swing.JButton limpiar;
    private javax.swing.JButton listar;
    private org.jdesktop.swingx.JXTable tablaSimpatizantes;
    private javax.swing.JTextField totalSim;
    // End of variables declaration//GEN-END:variables
}
